package com.sb.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;


public class Utils {
    /**
     * urlEncode
     *
     * @param str
     * @param encoding
     * @return
     */
    public static String urlEncode(String str, String encoding) {
        String urlStr = "";
        try {
            urlStr = URLEncoder.encode(str, encoding);
        } catch (UnsupportedEncodingException e) {

        }
        return urlStr;
    }

    /**
     * urlDecoder
     *
     * @param str
     * @param encoding
     * @return
     */
    public static String urlDecoder(String str, String encoding) {
        String urlStr = "";
        try {
            urlStr = URLDecoder.decode(str, encoding);
        } catch (UnsupportedEncodingException e) {

        }
        return urlStr;
    }

    /**
     * 元转换成分
     * @param yuan
     * @return
     */
    public static String YuanToFen(String yuan){
        if (yuan == ""){
            return null;
        }
        double d1 = Double.valueOf(yuan).doubleValue();
        double fen = d1 * 100;
        return String.valueOf(Math.round(fen));
    }
}
